package com.example.controller;

import com.example.entity.User;
import com.example.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@Slf4j
public class UserController {
    @Autowired
    UserMapper userMapper;

    @RequestMapping("hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }

    @RequestMapping("/the")
    public String getMsg(Model model, HttpSession session){
        //你好,春姑
        model.addAttribute("msg","你好,春姑");
        session.setAttribute("sess","lucy");
        //将person对象传递到thyme.html中

        User user = new User();
        user.setUname("安炳毅");
        user.setSex("男");
        user.setAge(55);
        user.setHiredate(new Date());


        model.addAttribute("person",user);
        return "thylm";
    }
    @GetMapping("/index")
    public String index(){
        return "index";
    }

    @GetMapping("/detail")
    public String  detail(Integer id, Model model) {
        User person = new User();
        model.addAttribute("person",person);
        List<User> list=userMapper.findAll();
        //传递list集合到html页面
        model.addAttribute("list",list);
        log.info(id+"");
        return "thylm";
    }
}
